import http from "@/utils/http";
import type {
  SalesOutStoreParamsType,
  SalesOutStoreAddParamsType,
  SalesOutStoreUpdateParamsType,
  PaginationType
} from "./params";
import { headerCommon, headerMaster } from "../header";
import {
  SalesOutStoreResponseData,
  SalesOutStoreAddResponceData,
  SalesOutStoreUpdateResponceData,
} from "./res";

// 标准写法
enum API {
  GET_SALESOUTSTORE_List_API = "/1.1/classes/salesOutStore",
  POST_SALESOUTSTORE_ADD_API = "/1.1/classes/salesOutStore",
  DELETE_SALESOUTSTORE_API = "/1.1/classes/salesOutStore",
  PUT_SALEOUTSTORE_UPDATE_API = "/1.1/classes/salesOutStore",
}

// example
//获取销售出库列表
export const getSalesOutStoreListApi = (data?: SalesOutStoreParamsType, params?: PaginationType) =>
  http.get<any, SalesOutStoreResponseData>(
    API.GET_SALESOUTSTORE_List_API +
    `${data ? `?where=${JSON.stringify(data)}` : ""}`,
    {
      headers: headerCommon,
      ...(params ? { params: { limit: params.pageSize, skip: (params.currentPage - 1) * params.pageSize } } : {})
    }
  );

//新增销售出库
export const postSalesOutStoreAddApi = (data: SalesOutStoreAddParamsType) =>
  http.post<any, SalesOutStoreAddResponceData>(
    API.POST_SALESOUTSTORE_ADD_API,
    data,
    {
      headers: headerCommon,
    }
  );

//更新销售出库
export const putSalesOutStoreUpdateApi = (
  data: SalesOutStoreUpdateParamsType
) =>
  http.put<any, SalesOutStoreUpdateResponceData>(
    API.PUT_SALEOUTSTORE_UPDATE_API + `/${data.objectId}`,
    data,
    {
      headers: headerMaster,
    }
  );

// 删除新增入库
export const deleteSalesOutStoreApi = (objectId: string) =>
  http.delete<any, any>(API.DELETE_SALESOUTSTORE_API + `/${objectId}`, {
    headers: headerMaster,
  });
